<template>
	<view>
		<u-list>
			<u-list-item>
				<u-cell :title="title" icon="map" @click="fetchPosition"></u-cell>
			</u-list-item>
			<u-search :placeholder="searchT" v-model="keyword"></u-search>
			<qiao-address :letter="'A'" @confirm="confrim"></qiao-address>
		</u-list>

	</view>
</template>

<script>
	const chooseLocation = requirePlugin('chooseLocation');
	export default {
		data() {
			return {
				keyword: '',
				searchT: "城市·车站的中文或拼音",
				title: "获取当前位置"
			}
		},
		onLoad() {

		},
		methods: {
			confrim(e) {
				console.log(e) //=>{"code": "310100","name": "上海市"}
				uni.$emit('update', {
					msg: e.name
				})
				uni.navigateBack({
					delta: 1
				})
			},
			fetchPosition() {
				const key = 'PEGBZ-FEG3I-VF3GR-UHIBH-DLN23-TXFFW'; //使用在腾讯位置服务申请的key
				const referer = 'asd'; //调用插件的app的名称
				const location = JSON.stringify({
					latitude: 39.89631551,
					longitude: 116.323459711
				});
				const category = '生活服务,娱乐休闲';

				uni.navigateTo({
					url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&location=' +
						location + '&category=' + category
				});
			},
		},


		onShow() {
			const _this = this
			const location = chooseLocation.getLocation(); // 如果点击确认选点按钮，则返回选点结果对象，否则返回null
			console.log("选点城市", location);
			if (location) {
				// uni.switchTab({
				// 	url: '/pages/index/index?city=' + location.city
				// })
				_this.searchT = location.city
				_this.title = location.city
			}

		},
		onUnload() {
			// 页面卸载时设置插件选点数据为null，防止再次进入页面，geLocation返回的是上次选点结果
			chooseLocation.setLocation(null);
		}
	}
</script>

<style>

</style>